package com.open.source.kafka.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;

/**
 * @author ZonLen since on 2022/8/6 上午10:13
 */
@Slf4j
public class KafkaProducerListener implements ProducerListener<String, String> {

  @Override
  public void onSuccess(ProducerRecord<String, String> producerRecord,
      RecordMetadata recordMetadata) {
    log.info("topic:{}, partition:{}, offset:{}", producerRecord.topic(),
        producerRecord.partition(), recordMetadata.offset());
  }

  @Override
  public void onError(ProducerRecord<String, String> producerRecord, RecordMetadata recordMetadata,
      Exception exception) {
    log.error("topic:{}, partition:{}, exp:{}", producerRecord.topic(),
        producerRecord.partition(), exception);
  }
}
